package com.vm.adapter;

import java.util.List;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.vm.commons.VMConst;
import com.vm.utils.MyDisplayImageOptions;
import com.wwtscapp.apk.R;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

@SuppressLint("InflateParams")
@SuppressWarnings("deprecation")
public class ImageAdapter extends BaseAdapter {
	private List<String> imageUrls; // 图片地址list
	private Context context;
	private ImageAdapter self;
	// public static String[]
	// imageUrl={"goods/201411/19/03633675-7bd8-45d0-80b6-5c98989dae7d_0.png","goods/201411/19/03633675-7bd8-45d0-80b6-5c98989dae7d_0.png","goods/201411/19/03633675-7bd8-45d0-80b6-5c98989dae7d_0.png","goods/201411/19/03633675-7bd8-45d0-80b6-5c98989dae7d_0.png"};
	public static String[] imageUrl;
	Uri uri;
	Intent intent;
	ImageView imageView;

	public ImageAdapter(Context context, String[] imageUrl) {
		this.context = context;
		this.self = this;
		ImageAdapter.imageUrl = imageUrl;
	}

	public int getCount() {
		return Integer.MAX_VALUE;
	}

	public Object getItem(int position) {
		return imageUrls.get(position % imageUrl.length);
	}

	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("HandlerLeak")
	private Handler mHandler = new Handler() {
		public void handleMessage(Message msg) {
			try {
				switch (msg.what) {
				case 0: {
					self.notifyDataSetChanged();
				}
					break;
				}

				super.handleMessage(msg);
			} catch (Exception e) {
			}
		}
	};

	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.item,
					null); // 实例化convertView
			Gallery.LayoutParams params = new Gallery.LayoutParams(
					Gallery.LayoutParams.WRAP_CONTENT,
					Gallery.LayoutParams.WRAP_CONTENT);
			convertView.setLayoutParams(params);
			convertView.setTag(imageUrl);

		} else {
		}
		imageView = (ImageView) convertView.findViewById(R.id.gallery_image);
		Bitmap bitmap = ImageLoader.getInstance().loadImageSync(
				VMConst.URL + imageUrl[position % imageUrl.length],
				MyDisplayImageOptions.getInstance());
		imageView.setImageBitmap(bitmap);
		// ((GoodsDetailsActivity)context).changePointView(position %
		// imageUrl.length);
		return convertView;

	}
}